using System;
using KJFramework.Dynamic.Contracts;
using KJFramework.IO.Helper;
using KJFramework.Logger;
using KJFramework.Net.Cloud.Processors;
using KJFramework.Platform.Client.ProtocolStack;
using KJFramework.Platform.Deploy.DSC.ProtocolStack;

namespace KJFramework.Platform.Deploy.DSC.CP.Client.Processors
{
    public class ClientGetDeployNodesRequestMessageProcessor : FunctionProcessor<ClientMessage>
    {
        #region Overrides of FunctionProcessor<ClientMessage>

        public override ClientMessage Process(Guid id, ClientMessage message)
        {
            try
            {
                IComponentTunnelContract contract = Global.ComponentInstance.GetTunnel("DSC.Components.Connector");
                if (contract == null)
                {
                    ConsoleHelper.PrintLine("Can not transport a object to component tunnel, beacuse this tunnel is null. #name: DSC.Components.Connector.", ConsoleColor.DarkRed);
                    return null;
                }
                DSCGetDeployNodesRequestMessage requestMessage = new DSCGetDeployNodesRequestMessage();
                requestMessage.Header.ClientTag = message.Header.ClientTag;
                requestMessage.Header.TaskId = message.Header.TaskId;
                contract.Transport(requestMessage);
            }
            catch (System.Exception ex)
            {
                Logs.Logger.Log(ex);
                ConsoleHelper.PrintLine("Can not transport a object to component tunnel. Error message: \r\n" + ex.Message, ConsoleColor.DarkRed);
            }
            return null;
        }

        #endregion
    }
}